package com.hxzy.login;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.widget.RadioGroup;

import com.hxzy.frame.fragmentMe;
import com.hxzy.frame.fragmentMeasure;
import com.hxzy.frame.fragmentObserve;
import com.hxzy.frame.fragmentRecord;


/**
 * Created by user on 2016/9/12.
 */

public class activity_fragment extends FragmentActivity {
        private RadioGroup bottomgroup;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame);
        findView();
        initView();

    }

    private void findView() {
        bottomgroup= (RadioGroup) findViewById(R.id.bottom_group);
    }

    private void showFragment(Fragment fragment) {
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.frame,fragment);
        fragmentTransaction.commit();
    }

    private void initView(){
        bottomgroup.setOnCheckedChangeListener(onCheckedChangeListener);
        showFragment(new fragmentMeasure());
    }
         ;
    RadioGroup.OnCheckedChangeListener onCheckedChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId) {
                case R.id.item_measure:
                    showFragment(new fragmentMeasure());
                    break;
                case R.id.item_observe:
                    showFragment(new fragmentObserve());
                    break;
                case R.id.item_record:
                    showFragment(new fragmentRecord());
                    break;
                case R.id.item_me:
                    showFragment(new fragmentMe());
                    break;
            }
        }
    };
}